package com.bwie;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2025/5/6 10:34
 */

public class IdTestApp {

    /**
     * @description 生成UUID
     * @params []
     * @return void
     * @author 军哥
     * @date 2025/5/6 10:46
     */
    @Test
    public void makeUUID() {
        for (int index = 0; index < 10; index++) {
            String s = UUID.randomUUID().toString();
            System.out.println(s);
        }
    }

    /**
     * 雪花算法
     */
    @Test
    public void makeSnowId() {
        Snowflake snowflake = new Snowflake(1, 1);
        for (int index = 0; index < 10; index++) {
            long snowId = snowflake.nextId();
            System.out.println(snowId);
        }
    }

    /**
     * @description 订单编号
     * @params []
     * @return void
     * @author 军哥
     * @date 2025/5/6 10:50
     */
    @Test
    public void makeOrderCode() {
        //SNyyyyMMddHHmmss + 6位随机数

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

        for (int index = 0; index < 10; index++) {
            String code = "SN" + dateFormat.format(new Date());
            code += RandomUtil.randomNumbers(6);
            System.out.println(code);
        }

    }

}
